package com.jie.jie.mvp.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jie.jie.R;
import com.jie.jie.mvp.model.MvpdataBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by jie on 2017/1/22.
 */

public class MvpGanhuoRvAdapter extends RecyclerView.Adapter<MvpGanhuoRvAdapter.ViewHolder> {
    private List<MvpdataBean.ResultsBean> mvpdataBeen;
    private Context context;
    private ItemClick itemClick;

    public void setItemClick(ItemClick itemClick) {
        this.itemClick = itemClick;
    }

    public MvpGanhuoRvAdapter(List<MvpdataBean.ResultsBean> mvpdataBeen, Context context) {
        this.mvpdataBeen = mvpdataBeen;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.mvp_item1, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.mvpTv.setText(mvpdataBeen.get(position).getDesc());
        holder.mvpTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClick != null) {
                    itemClick.click(v,mvpdataBeen.get(position).getUrl());
                }
            }
        });

    }

    public interface ItemClick {
        void click(View view, String url);
    }

    @Override
    public int getItemCount() {
        return mvpdataBeen.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.mvp_tv)
        TextView mvpTv;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
